package lol.clann.minecraft.springboot.plugin.module.devtools;

import java.io.*;

/**
 *
 * @author pyz
 * @date 2019/5/27 11:23 PM
 */
public class Dumpper implements AutoCloseable {
    private final File file;
    private final BufferedWriter bufferedWriter;

    public Dumpper(File file) throws IOException {
        this.file = file;
        if (!file.exists()) {
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
            file.createNewFile();
        }
        bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
    }

    public void print(String str) throws IOException {
        bufferedWriter.write(str);
    }

    public void newLine() throws IOException {
        bufferedWriter.newLine();
    }

    @Override
    public void close() throws Exception {
        bufferedWriter.close();
    }
}
